const SHA512 = require("crypto-js/sha512")

class UrlConfig {
    baseURL: string;
    photoBase: string;

    constructor(baseURL: string, photoBase: string) {
        this.baseURL = baseURL;
        this.photoBase = photoBase;
    }

    getUrlFor(path: string, params?: any){
        let res =  `${this.baseURL}${path}`;
        if (params) res+='?';
        for (const paramsKey in params) {
            res += `${encodeURIComponent(paramsKey)}=${encodeURIComponent(params[paramsKey])}&`;
        }
        return res;
    }

    getPhotoUrlFor(account: string | undefined, name: string | null | undefined){
        return this.photoBase+"/"+account+"/avatar/"+name;
    }
}

const urlConfig = new UrlConfig("https://lingwu.pro/api/station", "https://lingwu.pro/PUBLIC/station/photos");

const encoder = {
    enc: function (password: string) {
        return SHA512(password).toString();
    }
}

export {urlConfig, encoder}